package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.QtType;
import com.ruoyi.system.service.IQtTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 类型表Controller
 * 
 * @author ruoyi
 * @date 2021-11-18
 */
@RestController
@RequestMapping("/system/type")
public class QtTypeController extends BaseController
{
    @Autowired
    private IQtTypeService qtTypeService;

    /**
     * 查询类型表列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(QtType qtType)
    {
        startPage();
        List<QtType> list = qtTypeService.selectQtTypeList(qtType);
        return getDataTable(list);
    }

    /**
     * 导出类型表列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "类型表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(QtType qtType)
    {
        List<QtType> list = qtTypeService.selectQtTypeList(qtType);
        ExcelUtil<QtType> util = new ExcelUtil<QtType>(QtType.class);
        return util.exportExcel(list, "类型表数据");
    }

    /**
     * 获取类型表详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") String typeId)
    {
        return AjaxResult.success(qtTypeService.selectQtTypeByTypeId(typeId));
    }

    /**
     * 新增类型表
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "类型表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody QtType qtType)
    {
        return toAjax(qtTypeService.insertQtType(qtType));
    }

    /**
     * 修改类型表
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "类型表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody QtType qtType)
    {
        return toAjax(qtTypeService.updateQtType(qtType));
    }

    /**
     * 删除类型表
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "类型表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable String[] typeIds)
    {
        return toAjax(qtTypeService.deleteQtTypeByTypeIds(typeIds));
    }
}
